<template>
  <div>
    <div class="top" style="background-image: url(http://127.0.0.1:8080/ipfs/QmbszzCupvWnog4Qgx1YWz4rYSdkCaFUqRLFHwCNbx36vk)">
      <div class="avatar">
        <el-avatar :size="100" :src="circleUrl" ></el-avatar>
      </div>
      <!-- <div style="width:200px;position: absolute; left: 1320px; top: 230px;color:gray;font-size:13px">
        <span>展示我的NFT</span>
        <el-switch
          v-model="seenft"
          @change="test"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </div> -->
          <el-tag style="position: absolute; left: 1200px; top: 20px;"
      ><i class="el-icon-connection" ></i>{{ "    " + web3.coinbase }}
    </el-tag>
      <div style="position: absolute; left: 640px; top: 275px;">
         <p
      style="font-size: 25px; margin-block-start: 10px; margin-block-end: 10px; "
    >
      {{userName}}
    </p>
   
 <p style="margin-left: 0px;">在这里，可查看我的所有数字资产</p>
    </div>
    
    </div>
    
    <div style="height: 60px;margin-top:50px"></div>
   

    <el-collapse-transition>
      <div>
        <div
          class="every"
          v-for="(nft, i) in nfts"
          :key="i"
          style="
            height: 315px;
            width: 320px;
            float: left;
            margin-left: 100px;
            border-color: balck;
            box-shadow: 5px 5px 5px 5px #e4e7ed;
            border-radius: 10px;
            margin-top: 50px;
          "
        >
          <el-image
            :src="nft[4]"
            lazy
            style="width: 320px; height: 215px; border-radius: 10px 10px 0 0"
          ></el-image>
          <p>{{ nft[3] }}</p>
          <p style="color: gray; font-size: 2px">{{nft[5]}}</p>
        </div>
      </div>
    </el-collapse-transition>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //seenft: false,
      nfts: [],
      nftresult: null,
      nftsid: [],
      currentDate: new Date(),
      circleUrl:"",
      userName:'',
    };
  },
  created() {},
  async mounted() {
    console.log("dispatching getContractInstance");
    this.$store.dispatch("getContractInstance");
     if (!this.$store.state.contractInstance) {
        console.log("dispatching getContractInstance");
        await this.$store.dispatch("getContractInstance");
      }
    this.getUserNft();
    console.log(this.$store.state.web3.coinbase == 0x35b75D5670035186079103C052702E47A7195147);
     if(this.$store.state.web3.coinbase == 0x35b75D5670035186079103C052702E47A7195147){
        this.circleUrl = 'http://127.0.0.1:8080/ipfs/QmbYiCBha6CURFLxYVmEQftm58MbWDRnwCwNzuXKUsBg3P';
        this.userName = 'Mary';
     }
     else if(this.$store.state.web3.coinbase == 0x1c05E7aE5c320eFf0715902fD7c0F3A9B79f01aB){
        this.circleUrl = 'http://127.0.0.1:8080/ipfs/QmVAgHbP2KXtq1a1NsBgAb3dNqfKMurhatFeHVZUdKPQJH';
        this.userName = 'Jack';
     }
          
  },
  computed: {
    balance() {
      return parseInt(this.$store.state.web3.balance);
    },
    web3() {   
      return this.$store.state.web3;
    },
  },
  methods: {
    async test() {
      this.nfts = [];
      await this.getUserNft();
      //console.log(this.nfts);
    },

    async getNFT(nid, index) {
      let that = this;
      await this.$store.state.contractInstance().NFTS.call(
        nid, //用call返回一个结果，不使用call，返回的则是交易id
        {
          //gas: 300000,
          from: this.$store.state.web3.coinbase,
        },
        function (err, res) {
          that.nfts.push(res);
        }
      );
      // console.log(this.returnurl)
    },
    async getUserNft() {
      let that = this;
      console.log('getUserNft:web3.coinbase:'+ this.$store.state.web3.coinbase);
        // getUserProfile(this.$store.state.web3.coinbase)
      //  console.log(this.$store.state.web3.coinbase == 0x35b75D5670035186079103C052702E47A7195147)
      // if(this.$store.state.web3.coinbase == 0x35b75D5670035186079103C052702E47A7195147)
      //    this.circleUrl = 'http://127.0.0.1:8080/ipfs/QmREDiofRCTMjytNBUejNcpDb8pGFXcW45wNH6ChsSM7p4';
      //    else if(this.$store.state.web3.coinbase == 0x1c05E7aE5c320eFf0715902fD7c0F3A9B79f01aB)
      //     this.circleUrl = 'http://127.0.0.1:8080/ipfs/QmevgUKZQAiwTSQtCNDNZZJ3RvFQg1TbEJpBBE4xzgNaSo';
      // console.log(this.circleUrl)
      await this.$store.state.contractInstance().findByAddress.call(
        {
          gas: 300000,
          from: this.$store.state.web3.coinbase,
        },
        function (err, res) {
          that.nftsid = res;

          res.forEach((item, index) => {
            console.log("item = " + parseInt(item));

            that.getNFT("" + parseInt(item), index);
          });

          //console.log(res)
        }
      );
    },
     getUserProfile(coinbase){
        if(coinbase === '0x35b75D5670035186079103C052702E47A7195147')
        this.circleUrl = 'http://127.0.0.1:8080/ipfs/QmREDiofRCTMjytNBUejNcpDb8pGFXcW45wNH6ChsSM7p4';
     }
  },
};
</script>

<style scoped>
.top {
  position: relative;
  background-image: url("http://127.0.0.1:8080/ipfs/QmcjuMDQEuxuKeLsjR34o4hHwCaG7K6KADuWeQprjgo1kx");
  height: 220px;
  background-color: rgb(145, 229, 229);
}

.avatar {
  position: absolute;
  left: 716px;
  top: 180px;
}

.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
.NFTSimg {
  margin: 20px, auto;
  padding: 20px;
}
.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409eff;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}
</style>